package com.stylefeng.guns.modular.goods.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.goods.model.SkuSafeguard;
import com.stylefeng.guns.modular.goods.service.ISkuSafeguardService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-09-05 16:09:48
 */
@Controller
@RequestMapping("/skuSafeguard")
public class SkuSafeguardController extends BaseController {

    private String PREFIX = "/goods/skuSafeguard/";

    @Autowired
    private ISkuSafeguardService skuSafeguardService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "skuSafeguard.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/skuSafeguard_add")
    public String skuSafeguardAdd() {
        return PREFIX + "skuSafeguard_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/skuSafeguard_update/{skuSafeguardId}")
    public String skuSafeguardUpdate(@PathVariable Long skuSafeguardId, Model model) {
        SkuSafeguard skuSafeguard = skuSafeguardService.selectById(skuSafeguardId);
        model.addAttribute("item",skuSafeguard);
        LogObjectHolder.me().set(skuSafeguard);
        return PREFIX + "skuSafeguard_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return skuSafeguardService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SkuSafeguard skuSafeguard) {
        skuSafeguardService.insert(skuSafeguard);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long skuSafeguardId) {
        skuSafeguardService.deleteById(skuSafeguardId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SkuSafeguard skuSafeguard) {
        skuSafeguardService.updateById(skuSafeguard);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{skuSafeguardId}")
    @ResponseBody
    public Object detail(@PathVariable("skuSafeguardId") Long skuSafeguardId) {
        return skuSafeguardService.selectById(skuSafeguardId);
    }
}
